import axios from 'axios'
import { ElMessage } from "element-plus";

// 创建axios实例
const requestMock = axios.create({
    baseURL:'/mock',
    timeout: 30000
})

// 请求拦截器
requestMock.interceptors.request.use(
    (config) => {
        return config
    }
)

// 响应拦截器
requestMock.interceptors.response.use(
    (response) => {
        if(response.status === 200 && 20000){
            return response.data;
        } else {
            ElMessage({
                type:'error',
                message:'请求失败'
            })
        }
    },
    (error) =>{
        if (error.message.indexOf('timeout') != -1) {
            ElMessage.error('网络超时');
        } else  if(error.message == 'Network Error') {
            ElMessage.error('网络连接错误');
        }
        return Promise.reject(error);
    }
)

export default requestMock;
